/*
 * stdlib.h
 *
 * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _STDLIB_H_
#define _STDLIB_H_

#include <mlcrt.h>
#include <stddef.h>
#include <stdint.h>
#include <malloc.h>
#include <errno.h>

char *__CRT_PUBLIC(itoa)(int value, char *str, int base);
char *__CRT_PUBLIC(ltoa)(long value, char *str, int base);
char *__CRT_PUBLIC(lltoa)(long long value, char *str, int base);
char *__CRT_PUBLIC(uitoa)(unsigned int value, char *str, int base);
char *__CRT_PUBLIC(ultoa)(unsigned long value, char *str, int base);
char *__CRT_PUBLIC(ulltoa)(unsigned long long value, char *str, int base);
int __CRT_PUBLIC(atoi)(const char *str);
long __CRT_PUBLIC(atol)(const char *str);
long long __CRT_PUBLIC(atoll)(const char *str);
long __CRT_PUBLIC(strtol)(const char *str, char **endptr, int base);
long long __CRT_PUBLIC(strtoll)(const char *str, char **endptr, int base);
unsigned long __CRT_PUBLIC(strtoul)(const char *str, char **endptr, int base);
unsigned long long __CRT_PUBLIC(strtoull)(const char *str, char **endptr, int base);

void __CRT_PUBLIC(qsort)(void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
void *__CRT_PUBLIC(bsearch)(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));

#define ATEXIT_MAX 32

int __CRT_PUBLIC(atexit)(void (*function)(void));
void __attribute__((__noreturn__)) __CRT_PUBLIC(exit)(int status);

typedef uint32_t pid_t;

pid_t __CRT_PUBLIC(getpid)(void);
pid_t __CRT_PUBLIC(getppid)(void);
pid_t __CRT_PUBLIC(fork)(void);

#endif
